package com.pagoamigo.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.pagoamigo.domain.Account;

@RequestMapping("/test/**")
@Controller
public class TestController {

    @RequestMapping(method = RequestMethod.POST, value = "{id}")
    public void post(@PathVariable Long id, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
    	
    }

    @RequestMapping(method = RequestMethod.GET)
    public String index() {
        return "test/index";
    }
    
    @RequestMapping(method = RequestMethod.GET, value = "/coso")
    public String coso(ModelMap uiModel) {
    	List<Account> boris = com.pagoamigo.domain.Account.findAccountsByUsernameEquals("boris").getResultList();
    	uiModel.put("coso", boris.isEmpty()?"No esta Boris":boris.get(0).getEmail());
        return "test/index";
    }
    
    @RequestMapping(method = RequestMethod.GET, value = "/nelson")
    public String nelson(ModelMap uiModel) {
    	List<Account> n = com.pagoamigo.domain.Account.findAccountsByUsernameEquals("nelson").getResultList();
    	uiModel.put("coso", n.isEmpty()?"No esta Nelson":n.get(0).getEmail());
        return "test/index";
    }
    
}
